<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <!--[if lt IE 9]>
    <script src="http://www.json.org/json2.js"></script>
    <![endif]-->
    <script type="text/javascript" src="../static/js/head.js"></script>
</head>
<body>
<section>
    <div>
        <blockquote>
            <div>
                <button ADP_BTN ADP_ICON="add" method="addEntity">增加</button>
            </div>
        </blockquote>

        <div class="adp-content">

            <form action="" method="post" id="queryForm"></form>

            <table id="queryTable"></table>


        </div>

    </div>
</section>


<div style="width: 600px;display: none;" id="mergeFormDiv">
    <br/>
    <form action="" method="post" id="mergeForm"></form>
</div>


</body>
</html>
<script type="text/javascript" src="../static/js/adp2.js"></script>
<script type="text/javascript">


    function onTabRedisplay() {
        window.location.reload();
        $.msg("here");
    }


    //    layui.layer.msg("这只是一个演示");
    var queryform = $("#queryForm").adpForm({
        layout: 'horizontal',
        elem: [
//            {type: "text",lable:"测试",name:"field1",placeholder:"helloworld"},
//            {type: "text",lable:"测试2",name:"field2",placeholder:"helloworld2"},
//            {type: "select",lable:"测试3",name:"field3",placeholder:"helloworld",data:[{key:"",value:""},{key:"0",value:"北京"},{key:"1",value:"天津"}]},
//            {type: "checkbox",lable:"测试4",data:[
//                    {name:"aihao[xiezuo]",value:"xiezuo",lable:"写作",checked:true},
//                    {name:"aihao[wan]",value:"wan",lable:"玩耍"}
//                ]
//            },
            {type: "text", lable: "测试2", name: "code", placeholder: "helloworld2"}
        ],
        button: [
            {type: "submit", lable: "查询", method: "queryTable", icon: 'query'},
            {type: "reset", lable: "重置", icon: 'query'},
            {type: "button", lable: "帮助", method: "testmethod", icon: 'query'},
            {type: "button", lable: "下载", method: "download"}
        ]

    });
    var mergeForm = $("#mergeForm").adpForm({
        layout: 'vertical',//布局方式，支持水平和垂直两种，水平时候不写
        elem: [
            {type: "text", lable: "测试1", name: "field1", verify: "required", placeholder: "请输入内容"},
            {type: "text", lable: "测试2", name: "field2", placeholder: "请输入内容"},
            {
                type: "select",
                lable: "测试3",
                name: "field3",
                placeholder: "请输入内容",
                verify: "required",
                data: [{key: "", value: ""}, {key: "0", value: "北京"}, {key: "1", value: "天津"}]
            },
            {
                type: "checkbox", lable: "测试4", data: [
                {name: "aihao[xiezuo]", value: "xiezuo", lable: "写作", checked: true},
                {name: "aihao[wan]", value: "wan", lable: "玩耍"}
            ]
            },
            {type: "switch", lable: "开关", name: "field5", value: "1", checked: true},
            {
                type: "radio", lable: "性别", data: [
                {name: "sex", value: "women", lable: "帅哥"},
                {name: "sex", value: "man", lable: "美女", checked: true}
            ]
            },
            {type: "textarea", lable: "描述xx", name: "desc", placeholder: "请输入内容xx"},
            {type: "date", lable: "日期", name: "date1", format: 'YYYY-MM-DD hh:mm:ss',istime:'true'},
            {type: "date", lable: "日期2", name: "date2", format: 'YYYY-MM-DD',istime:'false'},
            {type: "custom", lable: "擴展", html: "<div style='color:red;'>自定義內容</div>"},
            {type: "dept", lable: "部门", name: "dept", verify: "required"},
            {type: "uploader", lable: "上传1", name: "xxx", verify: "required"},
            {type: "uploader", lable: "上传2", name: "xxx2",showThumbnail:false},
            {type: "hidden", name: "id", value: ""}

        ],
        button: [
            {type: "submit", lable: "保存", method: "submitEditEntity"},
            {type: "reset", lable: "重置"},
            {type: "button", lable: "帮助", method: "testmethod"}
        ],
        verify: {//自定义验证,可选项目
            //加在普通div上也有效
            principal: function (value) {
                if ($("input[name*='principal']:checked").size() == 0) {
                    return '权限必须选择!';
                }
            },
            range: [/(.+){6,12}$/, '必须6到12位']
        }
    });


    var adptable = $("#queryTable").adpTable({
        service: "Resource",
        method: "list",
        enableCheckbox: true,
        pageSize: 5,
        loadCallBack:function (data) {
            $.msg("提示：这个页面演示了所有控件的用法");
        },
        columns: [
            {field: 'code', title: '名称', width: 180},
            {field: 'name', title: '密码', width: 80},
            {field: 'type', title: '是否激活', width: 100},
            {field: 'url', title: '拥有角色'},
            {
                title: '操作', width: 220, field: function (index, obj) {
                return '<button ADP_BTN ADP_ICON="update" method="updateEntity">增加</button>' +
                    '<button ADP_BTN ADP_ICON="delete" method="deleteEntity">增加</button>'
                    ;
            }
            }
        ]
    });

    adptable.load({});

    //    $("#queryTable").test(1);

    function addEntity() {
        var data = mergeForm.getData();
//        $.msg(JSON.stringify(data));
        mergeForm.reset();
        $("#mergeFormDiv").open("添加实体", {
            cancel: function (index, layero) {
                if (confirm('确定要关闭么')) { //只有当点击confirm框的确定时，该层才会关闭
                    layer.close(index)
                }
                return false;
            }
        });
    }
    function updateEntity(entity) {
        mergeForm.reset();
//        $.alert(JSON.stringify(adptable.getSelection()));
        $("#mergeFormDiv").open("更新实体");
        mergeForm.uploader.xxx.val("a3ebdf0af1aa489fa79e55cca8592ef1");

    }

    function deleteEntity(entity) {
        $.alert(JSON.stringify(entity));
    }

    function submitEditEntity(obj) {
//    alert(JSON.stringify(obj));
        $.confirm("确定要提交吗？", {title: "确认"}, function (index) {
            $.msg(JSON.stringify(obj));
            $.close(index);
            $("#mergeFormDiv").close();
        });

    }


    function testmethod() {
        $.alert("mm");
        mergeForm.uploader.xxx.val();
    }

    function queryTable(obj) {
        alert(JSON.stringify(obj));
    }

    function download(obj) {
        Download("Resource")("export")(queryform.getData());
    }

    $("#dept11").on("click", function (event) {
        //页面层
        layui.layer.open({
            type: 1,
            title: false,
            shade: 0.1,
//            skin: 'demo-class',
            shadeClose: true,
            area: ['320px', '240px'], //宽高
            content: '<ul id="deptTree"></ul>'
        });


        ADP.Deferred("Department")("getDepartmentTree")().done(function (data) {
            $("#deptTree").empty();
            layui.tree({
                elem: '#deptTree',
                nodes: data,
                click: function (node) {
                    alert(1);

                }
            });
        });

//        var rootdeptList = ADP.SV("Department")("getDepartmentTree")();
//        $("#deptTree").empty();
//        layui.tree({
//            elem: '#deptTree',
//            nodes: rootdeptList,
//            click:function (node) {
//                alert(1);
//
//            }
//        });
    });



</script>